package com.nisco.nio.socket.sendstring;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args)
        throws IOException {
        char[] charArray = new char[3];
        ServerSocket serverSocket = new ServerSocket(8088);
        System.out.println("accept begin " + System.currentTimeMillis());
        Socket socket = serverSocket.accept();
        System.out.println("accept end " + System.currentTimeMillis());

        InputStream inputStream = socket.getInputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        int readLen = inputStreamReader.read(charArray);
        while (readLen != -1) {
            System.out.println(new String(charArray, 0, readLen));
            readLen = inputStreamReader.read(charArray);
        }

        System.out.println("read end " + System.currentTimeMillis());
        inputStreamReader.close();
        inputStream.close();
        socket.close();
        serverSocket.close();

    }
}
